// pages/integralMall/mallDetail/mallDetail.js
const app = getApp()
import api from '../../../utils/api'
let apis = api.api;
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		autoplay: true,
		interval: 3000,
		duration: 1200,
		indicatorDots: true,
		vertical: false,
		shopIds: null,
		shopDetailId: null,
		shopDetail: [],
		buyNum: 1,
		shopTitle: '',
		shopScore: 0,
		shopPrice: 0,
		shopPic: '',
	},
	// getData(option) {

	// },
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(option) {
		console.log('onload', option)
		// https://dageda.api.hjdz.ltd/goods/detail
		var that = this;
		that.setData({
			shopIds: option.id
		})
		console.log('shopIds',that.data.shopIds)
		let url = apis.host + 'goods/detail';
		let datas = {
			gid: that.data.shopIds,
			/* 是	string	商品ID */
		}
		apis.request(url, datas, 'POST').then(function(res) {
			console.log('获取商品详情成功', res)
			that.setData({
				shopDetail: res.data,
				shopDetailId: res.data.id,
				shopTitle: res.data.title,
				shopScore: res.data.score,
				shopPrice: res.data.pricce,
				shopPic: res.data.pic
			})
		}).catch(function(res) {
			console.log('获取失败', res)
		})
		var data = {
			"datas": [{
					"id": 1,
					"imgurl": "https://cdn.oss.dgddaijia.com/icons/custom_bg.png"
				},
				{
					"id": 2,
					"imgurl": "https://cdn.oss.dgddaijia.com/icons/custom_bg.png"
				},
				{
					"id": 3,
					"imgurl": "https://cdn.oss.dgddaijia.com/icons/custom_bg.png"
				},
				{
					"id": 4,
					"imgurl": "https://cdn.oss.dgddaijia.com/icons/custom_bg.png"
				}
			]
		};
		that.setData({
			lunboData: data.datas
		})
	},
	onChange(event) {
		var that = this
		that.setData({
			buyNum: event.detail
		})
		console.log(event.detail);
	},
	buy() {
		var that = this;
		let shopId = that.data.shopDetailId;
		let buyNum = that.data.buyNum;
		let title = that.data.shopTitle;
		let score = that.data.shopScore;
		let price = that.data.shopPrice;
		let pic = that.data.shopPic;
		wx.navigateTo({
			url: '/pages/integralMall/submitOrder/submitOrder?pic=' + pic + '&s_num=' + buyNum +
				'&s_tit=' + title + '&s_score=' + score + '&s_price=' + price + '&s_id=' + shopId
		})
	},
})
